package cn.iocoder.yudao.module.biz.controller.admin.risk.riskPointType;

import cn.iocoder.yudao.module.biz.controller.admin.risk.riskPointType.vo.*;
import cn.iocoder.yudao.module.biz.convert.risk.riskPointType.BizRiskPointTypeConvert;
import cn.iocoder.yudao.module.biz.dal.dataobject.risk.riskPointType.BizRiskPointTypeDO;
import cn.iocoder.yudao.module.biz.service.risk.riskPointType.BizRiskPointTypeService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;


@Api(tags = "管理后台 - 风险点类型")
@RestController
@RequestMapping("/biz/riskPointType")
@Validated
public class BizRiskPointTypeController {

    @Resource
    private BizRiskPointTypeService riskPointTypeService;

    @PostMapping("/create")
    @ApiOperation("创建风险点类型")
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:create')")
    public CommonResult<String> createRiskPointType(@Valid @RequestBody BizRiskPointTypeCreateReqVO createReqVO) {
        return success(riskPointTypeService.createRiskPointType(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新风险点类型")
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:update')")
    public CommonResult<Boolean> updateRiskPointType(@Valid @RequestBody BizRiskPointTypeUpdateReqVO updateReqVO) {
        riskPointTypeService.updateRiskPointType(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除风险点类型")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:delete')")
    public CommonResult<Boolean> deleteRiskPointType(@RequestParam("id") String id) {
        riskPointTypeService.deleteRiskPointType(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得风险点类型")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:query')")
    public CommonResult<BizRiskPointTypeRespVO> getRiskPointType(@RequestParam("id") String id) {
        BizRiskPointTypeDO riskPointType = riskPointTypeService.getRiskPointType(id);
        return success(BizRiskPointTypeConvert.INSTANCE.convert(riskPointType));
    }

    @GetMapping("/list")
    @ApiOperation("获得风险点类型列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:query')")
    public CommonResult<List<BizRiskPointTypeRespVO>> getRiskPointTypeList(@RequestParam("ids") Collection<String> ids) {
        List<BizRiskPointTypeDO> list = riskPointTypeService.getRiskPointTypeList(ids);
        return success(BizRiskPointTypeConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得风险点类型分页")
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:query')")
    public CommonResult<PageResult<BizRiskPointTypeRespVO>> getRiskPointTypePage(@Valid BizRiskPointTypePageReqVO pageVO) {
        PageResult<BizRiskPointTypeDO> pageResult = riskPointTypeService.getRiskPointTypePage(pageVO);
        return success(BizRiskPointTypeConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出风险点类型 Excel")
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:export')")
    @OperateLog(type = EXPORT)
    public void exportRiskPointTypeExcel(@Valid BizRiskPointTypeExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizRiskPointTypeDO> list = riskPointTypeService.getRiskPointTypeList(exportReqVO);
        // 导出 Excel
        List<BizRiskPointTypeExcelVO> datas = BizRiskPointTypeConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "风险点类型.xls", "数据", BizRiskPointTypeExcelVO.class, datas);
    }

    @GetMapping("/getAllPointType")
    @ApiOperation("获得风险点类型")
    @PreAuthorize("@ss.hasPermission('biz:risk-point-type:query')")
    public CommonResult<List<BizRiskPointTypeRespVO>> getAllPointType() {
        List<BizRiskPointTypeDO> list = riskPointTypeService.getAllPointType();
        return success(BizRiskPointTypeConvert.INSTANCE.convertList(list));
    }
}
